{% extends '@theme/base.html.twig' %}

{% block body %}
<div class="container-fluid pt-4 bg-light">
    <div class="container">
        <div class="row">
            <div class="col-md-3">
                <h3 class="mb-4">Profile</h3>
                <div class="card bg-white mb-4">
                    <div class="card-body">
                        <ul class="list-unstyled">
                            <li><span data-user-email="{{ user.email }}">{{ user.email }}</span></li>
                            {% if user.fbAppId %}
                                <li><i class="fab fa-facebook-square"></i> Connected</li>
                            {% endif %}
                            {% if user.linkedInAppId %}
                            <li>Linked <i class="fab fa-linkedin"></i> Connected </li>
                            {% endif %}

                            <a class="btn btn-outline-danger btn-block mt-4" href="{{ url('logout') }}"><small>Logout</small></a>
                        </ul>
                    </div>
                </div>
                {% if throttled and extraOffersCount <= 0 %}
                <div class="alert alert-warning small text-dark">
                    No offers left, and you really need to post this amazing job offer? <br/>
                    No problem, email us at <a href="mailto:{{ contact_email }}">{{ contact_email }}</a> and we might
                    find for you few instant offers.
                </div>
                {% endif %}
                <p class="mt-4">If you have any questions please check our <a href="{{ url('faq') }}">FAQ</a> section.</p>
            </div>
            <div class="col-md-9">
                <h2 class="mb-4">Features</h2>
                <div class="row mb-4">
                    <div class="col-3">
                        <div class="bg-white border mb-4">
                            <div class="small text-right pt-2 pr-2">
                                {%
                                    set regularOffers = "Job Offers you can post here and now. If you don't have any regular offers left, email us at <a target=\"_blank\" href=\"mailto:" ~ contact_email ~ "\">" ~ contact_email ~ "</a> so we can grant you some
                                       <span class=\"font-weight-bold text-blue\">Instant Offers</span>."
                                %}
                                <button type="button"
                                    class="btn btn-link btn-sm"
                                    data-toggle="popover"
                                    data-trigger="focus"
                                    title="Regular Offers"
                                    data-content="{{ regularOffers }}"
                                    data-placement="right"
                                >
                                    <i class="far fa-question-circle"></i>
                                </button>
                            </div>
                            <div class="text-center pt-2 pb-4">
                                <h2><i class="far fa-file"></i></h2>
                                <h3 class="font-weight-light">{{ offersLeft }} left</h3>
                                <h5 class="font-weight-light">Regular Offers</h5>
                            </div>
                        </div>
                    </div>
                    <div class="col-3">
                        <div class="bg-white border mb-4">
                            <div class="small text-right pt-2 pr-2">
                                <button type="button"
                                        class="btn btn-link btn-sm"
                                   data-toggle="popover"
                                   data-trigger="focus"
                                   title="Instant Offers"
                                   data-content="All offers are free however regular offers are throttled and auto regenerated.
                                       Instant Offers let you post new job offers even if you don't have any regular offers left.
                                       Instant Offers can expire, don't keep them for too long!"
                                   data-placement="right"
                                >
                                    <i class="far fa-question-circle"></i>
                                </button>
                            </div>
                            <div class="text-center pt-2 pb-4">
                                <h2><i class="fas fa-redo text-blue"></i></h2>
                                <h3 class="font-weight-light">{{ extraOffersCount }} left</h3>
                                <h5 class="font-weight-light">Instant Offers</h5>
                            </div>
                        </div>
                        {% if extraOffer %}
                            <div class="text-center">
                                <small>Expires: {{ extraOffer.expiresAt|time_diff }}</small>
                            </div>
                        {% endif %}
                    </div>
                    <div class="col-3">
                        <div class="bg-white border mb-4">
                            <div class="small text-right pt-2 pr-2">
                                <button type="button"
                                    class="btn btn-link btn-sm"
                                    data-toggle="popover"
                                    data-trigger="focus"
                                    title="Offer Auto Renew"
                                    data-content="Automatically renew expiring offers in order to extend offer life up to 6 weeks. One offer can be auto renewed maximum 2 times."
                                    data-placement="right"
                                >
                                    <i class="far fa-question-circle "></i>
                                </button>
                            </div>
                            <div class="text-center pt-2 pb-4">
                                <h2><i class="fas fa-tachometer-alt text-green"></i></h2>
                                <h3 class="font-weight-light">{{ offerAutoRenewsCount }} left</h3>
                                <h5 class="font-weight-light">Auto Renews</h5>
                            </div>
                        </div>
                    </div>
                </div>

                <hr />

                <h3 class="mb-4">Posted Offers - {{ totalOffers }}</h3>

                {% for offer in offers %}
                    <div class="row mt-4 mb-2">
                        <div class="col-md-4">
                            Name: <a href="{{ url('offer', {'offerSlug': offer.slug}) }}" >{{ offer.position.seniorityLevel|offer_seniority_level_name }} {{ offer.position.name }}</a>
                        </div>
                        <div class="col-md-4">
                        </div>
                        <div class="col-md-4">
                            Company: <a href="{{ offer.company.url }}" target="_blank">{{ offer.company.name }}</a>
                        </div>
                    </div>
                    <div class="row mb-2">
                        <div class="col-md-4">
                            Specialization: <a href="{{ url('specialization_offers', {specSlug: offer.specializationSlug}) }}">{{ offer.specializationSlug|specialization_name }}</a>
                        </div>
                        <div class="col-md-4">
                        </div>
                        <div class="col-md-4">
                            {% if offer.contact.isExternalSource %}
                                <a href="{{ offer.contact.url }}" target="_blank">External Source</a>
                            {% else %}
                                Received applications: {{ offer.applicationsCount }}
                            {% endif %}
                        </div>
                    </div>
                    <div class="row mb-2">
                        <div class="col-md-4">
                            Salary:
                            {% if offer.salary %}
                                {{ offer.salary.currencyCode }} {{ offer.salary.min|offer_salary_integer }} - {{ offer.salary.max|offer_salary_integer }}
                            {% else %}
                                Not defined
                            {% endif %}
                            {% if offer.salary %}
                                {% if offer.salary.isNet %}net{% else %}gross{% endif %} per {{ offer.salary.periodType }}
                            {% endif %}
                        </div>
                        <div class="col-md-4">
                        </div>
                        <div class="col-md-4">
                        </div>
                    </div>
                    <div class="row mb-2">
                        <div class="col-md-4">
                            <section>
                                Posted: {% include '@offers/offer/offer/_created_at.html.twig' with {offer: offer} only %}
                            </section>
                            <section>
                                Upcoming auto renews <i class="fas fa-tachometer-alt text-green"></i> : {{ offer|offer_auto_renews_left }}x
                                <button type="button"
                                    class="btn btn-link btn-sm"
                                    data-toggle="popover"
                                    data-trigger="focus"
                                    title="Offer Auto Renew"
                                    data-content="Number of times this offer is going to be automatically renewed after it expires. Extends offer lifetime up to 2 times."
                                    data-placement="right"
                                >
                                    <i class="far fa-question-circle "></i>
                                </button>
                            </section>
                            <section>
                                Used auto renews: {{ offer|offer_auto_renews_used }}x
                                <button type="button"
                                   class="btn btn-link btn-sm"
                                   data-toggle="popover"
                                   data-trigger="focus"
                                   title="Offer Auto Renew"
                                   data-content="Number of times this offer was already automatically renewed."
                                   data-placement="right"
                                >
                                    <i class="far fa-question-circle "></i>
                                </button>
                            </section>
                        </div>
                        <div class="col-md-4">
                        </div>
                        <div class="col-md-4">
                            <a class="btn btn-primary btn-sm btn-block" href="{{ url('offer_new', {specSlug: offer.specializationSlug, 'offer-slug': offer.slug }) }}">post again</a>
                            {% if offer|offer_older_than_hours(constant('ITOffers\\Offers\\Application\\Offer\\Offer::INSTANT_EDIT_TIME_HOURS')) == false %}
                                <a class="btn btn-primary btn-sm btn-block" href="{{ url('offer_edit', {specSlug: offer.specializationSlug, 'offer-slug': offer.slug })  }}"><i class="far fa-edit"></i> edit</a>
                            {% else %}
                                <a class="btn btn-primary btn-sm btn-block disabled" href="#" disabled="disabled"><i class="far fa-edit"></i> edit</a>
                            {% endif %}
                            <a class="btn btn-danger btn-sm btn-block " href="{{ url('offer_remove_confirmation', {offerSlug: offer.slug}) }}" data-remove-offer><i class="fas fa-times"></i> remove</a>
                            {% if offer|offer_older_than(itof.old_offer_days) == false and offer|offer_auto_renews_total < 2 and offerAutoRenewsCount > 0%}
                                <a class="btn btn-success btn-sm btn-block" href="{{ url('offer_assign_auto_renew', {offerSlug: offer.slug})  }}"><i class="fas fa-tachometer-alt text-black"></i> Add Auto Renew</a>
                            {% endif %}
                        </div>
                    </div>
                    <hr />
                {% else %}
                    <div class="alert alert-info text-center mb-4">
                        It looks you have not posted any offers so far.
                    </div>
                    <div class="text-center mb-4">
                        <a class="btn btn-primary pt-2 pb-2" href="{{ url('offer_post') }}"><small class="font-weight-bolder">Post a Job</small></a>
                    </div>
                {% endfor %}
                {% if offersMore > offers|length %}
                    <div class="mt-2 row mb-4">
                        <div class="col-md-6 text-left">
                            {% if showingOlder %}
                                <a class="btn btn-primary mr-2" href="{{ url('user_profile') }}">Show latest</a>
                            {% endif %}
                        </div>
                        <div class="col-md-6 text-right">
                            <a class="btn btn-secondary" href="{{ url('user_profile', {after: offers.last.id.toString}) }}">Show older</a>
                        </div>
                    </div>
                {% else %}
                    {% if showingOlder %}
                        <div class="mt-2 row mb-4">
                            <div class="col-md-6 text-left">
                                <a class="btn btn-primary" href="{{ url('user_profile') }}">Show latest</a>
                            </div>
                            <div class="col-md-6 text-right">
                            </div>
                        </div>
                    {% endif %}
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}